<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><link rel="shortcut icon" href="dlib-icon.ico"><meta name="verify-v1" content="02MiiaFNVzS5/u0eQhsy3/knioFHsia1X3DXRpHkE6I="><meta name="google-site-verification" content="DGSSJMKDomaDaDTIRJ8jDkv0YMx9Cz7OESbXHjjr6Jw"><title>dlib C++ Library
   - Networking</title><script language="JavaScript">

// ---------------------------------------------
// --- Name:    Easy DHTML Treeview           --
// --- Author:  D.D. de Kerf                  --
// --- Version: 0.2          Date: 13-6-2001  --
// ---------------------------------------------
function Toggle(node)
{
   // Unfold the branch if it isn't visible
   var next_node = node.nextSibling;
   if (next_node.style.display == 'none')
   {
      // Change the image (if there is an image)
      if (node.childNodes.length > 0)
      {
         if (node.childNodes.length > 0)
         { 
            if (node.childNodes.item(0).nodeName == "IMG")
            {
               node.childNodes.item(0).src = "minus.gif";
            }
         }
      }

      next_node.style.display = 'block';
   }
   // Collapse the branch if it IS visible
   else
   {
      // Change the image (if there is an image)
      if (node.childNodes.length > 0)
      {
         if (node.childNodes.length > 0)
         { 
            if (node.childNodes.item(0).nodeName == "IMG")
            {
               node.childNodes.item(0).src = "plus.gif";
            }
         }
      }

      next_node.style.display = 'none';
   }

}
function BigToggle(node)
{
   // Unfold the branch if it isn't visible
   var next_node = node.nextSibling;
   if (next_node.style.display == 'none')
   {
      // Change the image (if there is an image)
      if (node.childNodes.length > 0)
      {
         if (node.childNodes.length > 0)
         { 
            if (node.childNodes.item(0).nodeName == "IMG")
            {
               node.childNodes.item(0).src = "bigminus.gif";
            }
         }
      }

      next_node.style.display = 'block';
   }
   // Collapse the branch if it IS visible
   else
   {
      // Change the image (if there is an image)
      if (node.childNodes.length > 0)
      {
         if (node.childNodes.length > 0)
         { 
            if (node.childNodes.item(0).nodeName == "IMG")
            {
               node.childNodes.item(0).src = "bigplus.gif";
            }
         }
      }

      next_node.style.display = 'none';
   }

}
</script><style type="text/css">
   body {margin:0px;}
   pre {margin:0px;}

   ul.tree  li { list-style: none;  margin-left:10px;} 
   ul.tree  { margin:0px; padding:0px; margin-left:5px; font-size:0.95em; }
   ul.tree  li ul { margin-left:10px; padding:0px; }

   li#term { list-style: none; }

   div#component {
      background-color:white; 
      border: 2px solid rgb(102,102,102); 
      text-align:left;
      margin-top: 1.5em;
      padding: 0.7em;
   }

   div#question {
      background-color:white; 
      border: 2px solid rgb(102,102,102); 
      text-align:left;
      margin-top: 1.5em;
      margin-bottom: 90%;
      padding: 0.7em;
   }

   div#function {
      background-color:white; 
      border: 2px solid rgb(102,102,255); 
      text-align:left;
      margin-top: 0.3em;
      padding: 0.3em;
   }

   div#class {
      background-color:white; 
      border: 2px solid rgb(255,102,102); 
      text-align:left;
      margin-top: 0.3em;
      padding: 0.3em;
   }

   div#extension {
      background-color:#FDFDFD; 
      border: 1px solid rgb(102,102,102); 
      text-align:left;
      margin-top: 1.0em;
      padding: 0.7em;
   }

   div#logb {
      text-align:left;
      padding: 0.0em;
      float: left;
      background-color:#c0c0c0; 
      border: double ; 
      margin: 0.5em;
   }

   div#name {
      float: left;
   }
   div#line1 {
      float:left;
      width:100%;
      background-color:#dfdfdf; 
   }
   div#line2 {
      float:left;
      width:100%;
   }
   div#inc {
      float: right;
   }


   .code_box
   {
      color: black;
      margin: 1em 0.25in;
      padding: 0.5em;
      background: rgb(240,240,240);
      border-top: black dotted 1px;
      border-left: black dotted 1px;
      border-right: black solid 2px;
      border-bottom: black solid 2px;
   }



   .bdotted {border-bottom: 1px dotted}
   .bdashed {border-bottom: 1px dashed}
   .bsolid {border-bottom: 1px solid}
   .bdouble {border-bottom: 1px double}
   .bgroove {border-bottom: 1px groove}
   .bridge {border-bottom: 1px ridge}
   .binset {border-bottom: 1px inset}
   .boutset {border-bottom: 1px outset}

   div#row1 {
      background-color:#dfdfdf; 
   }
   div#row2 {
      background-color:#f2f2f2; 
   }

   div#typedefs {
      margin-left: 1.5em;
      margin-top: 0.2em;
      border: 1px dotted;
      width: 52em;
   }

   div#tdn {
      width: 10em;
   }

   .fullhr {
      clear: both;
   }

   body {
      text-align: center;
   }

   div#entire_page {
      width:62.5em;  
      text-align: left;
      margin-top: 0.4em;
      margin-left: auto;
      margin-right: auto;
   }
</style></head><body bgcolor="#EDF3EE"><a name="top"></a><div id="entire_page"><a href="http://dlib.net"><img src="dlib-logo.png"></a><table bgcolor="white" height="100%" bordercolor="#EDF3EE" CELLSPACING="0" CELLPADDING="10" style="border:0px;margin-top:2px"><tr height="100%"><td BGCOLOR="#F5F5F5" style="padding:7px; border: 1px solid rgb(102,102,102);" VALIGN="TOP" height="100%"><br><table WIDTH="145" height="100%"><tr><td VALIGN="TOP"><b>The Library</b><ul class="tree"><li><a href="algorithms.html">Algorithms</a></li><li><a href="api.html">API Wrappers</a></li><li><a href="bayes.html">Bayesian Nets</a></li><li><a href="compression.html">Compression</a></li><li><a href="containers.html">Containers</a></li><li><a href="graph_tools.html">Graph Tools</a></li><li><a href="imaging.html">Image Processing</a></li><li><a href="linear_algebra.html">Linear Algebra</a></li><li><a href="ml.html">Machine Learning</a></li><li><a href="metaprogramming.html">Metaprogramming</a></li><li><a href="other.html">Miscellaneous</a></li><li><a href="network.html">Networking</a></li><li><a href="optimization.html">Optimization</a></li><li><a href="parsing.html">Parsing</a></li></ul><br><b>Help/Info</b><ul class="tree"><li><a onclick="Toggle(this)" style="cursor: pointer;margin-left:-9px"><img src="plus.gif"><font color="green"><u>Examples: C++</u></font></a><ul style="display:none;"><li><a href="assignment_learning_ex.cpp.html">Assignment_Learning</a></li><li><a href="file_to_code_ex.cpp.html">Base64_Encoder</a></li><li><a href="bayes_net_ex.cpp.html">Bayesian_Network</a></li><li><a href="bayes_net_from_disk_ex.cpp.html">Bayesian_Network_From_Disk</a></li><li><a href="bayes_net_gui_ex.cpp.html">Bayesian_Network_GUI</a></li><li><a href="bridge_ex.cpp.html">Bridge</a></li><li><a href="bsp_ex.cpp.html">BSP</a></li><li><a href="compress_stream_ex.cpp.html#_top">Cmd_Line_Parser</a></li><li><a href="compress_stream_ex.cpp.html">Compress_Stream</a></li><li><a href="config_reader_ex.cpp.html">Config_File_Reader</a></li><li><a href="custom_trainer_ex.cpp.html">Custom_Trainers</a></li><li><a href="dir_nav_ex.cpp.html">Directory_Navigation</a></li><li><a href="empirical_kernel_map_ex.cpp.html">Empirical_Kernel_Map</a></li><li><a href="face_detection_ex.cpp.html">Face_Detection</a></li><li><a href="fhog_ex.cpp.html">FHOG_Feature_Extraction</a></li><li><a href="fhog_object_detector_ex.cpp.html">FHOG_Object_Detection</a></li><li><a href="graph_labeling_ex.cpp.html">Graph_Labeling</a></li><li><a href="gui_api_ex.cpp.html">GUI</a></li><li><a href="server_http_ex.cpp.html">HTTP_Server</a></li><li><a href="image_ex.cpp.html">Image</a></li><li><a href="iosockstream_ex.cpp.html">IO Socket Streams</a></li><li><a href="server_iostream_ex.cpp.html">IO Streams Server</a></li><li><a href="kcentroid_ex.cpp.html">Kernel_Centroid</a></li><li><a href="kkmeans_ex.cpp.html">Kernel_K-Means_Clustering</a></li><li><a href="krr_regression_ex.cpp.html">Kernel_Ridge_Regression</a></li><li><a href="krls_filter_ex.cpp.html">Kernel_RLS_Filtering</a></li><li><a href="krls_ex.cpp.html">Kernel_RLS_Regression</a></li><li><a href="krr_classification_ex.cpp.html">KRR_Classification</a></li><li><a href="learning_to_track_ex.cpp.html">Learning_to_Track</a></li><li><a href="linear_manifold_regularizer_ex.cpp.html">Linear_Manifold_Regularizer</a></li><li><a href="logger_ex.cpp.html">Logger</a></li><li><a href="logger_ex_2.cpp.html">Logger_Advanced</a></li><li><a href="logger_custom_output_ex.cpp.html">Logger_Custom_Output</a></li><li><a href="matrix_ex.cpp.html">Matrix</a></li><li><a href="matrix_expressions_ex.cpp.html">Matrix_Expressions</a></li><li><a href="member_function_pointer_ex.cpp.html">Member_Function_Pointer</a></li><li><a href="model_selection_ex.cpp.html">Model_Selection</a></li><li><a href="multiclass_classification_ex.cpp.html">Multiclass_Classification</a></li><li><a href="multithreaded_object_ex.cpp.html">Multithreaded_Object</a></li><li><a href="mlp_ex.cpp.html">Neural_Network</a></li><li><a href="least_squares_ex.cpp.html">Non-Linear Least Squares</a></li><li><a href="integrate_function_adapt_simp_ex.cpp.html">Numerical_Integration</a></li><li><a href="object_detector_ex.cpp.html">Object_Detector</a></li><li><a href="object_detector_advanced_ex.cpp.html">Object_Detector_Advanced</a></li><li><a href="one_class_classifiers_ex.cpp.html">One_Class_Classifiers</a></li><li><a href="svm_pegasos_ex.cpp.html">Online_SVM</a></li><li><a href="optimization_ex.cpp.html">Optimization</a></li><li><a href="parallel_for_ex.cpp.html">Parallel_For_Loops</a></li><li><a href="pipe_ex.cpp.html">Pipe</a></li><li><a href="pipe_ex_2.cpp.html">Pipe_2</a></li><li><a href="quantum_computing_ex.cpp.html">Quantum_Computing</a></li><li><a href="queue_ex.cpp.html">Queue</a></li><li><a href="rank_features_ex.cpp.html">Rank_Features</a></li><li><a href="rvm_ex.cpp.html">Relevance_Vector_Classification</a></li><li><a href="rvm_regression_ex.cpp.html">Relevance_Vector_Regression</a></li><li><a href="running_stats_ex.cpp.html">Running_Stats</a></li><li><a href="sequence_labeler_ex.cpp.html">Sequence_Labeling</a></li><li><a href="sequence_segmenter_ex.cpp.html">Sequence_Segmentation</a></li><li><a href="sockets_ex.cpp.html">Sockets</a></li><li><a href="sockstreambuf_ex.cpp.html">Sockstreambuf</a></li><li><a href="svm_sparse_ex.cpp.html">Sparse_Vectors</a></li><li><a href="std_allocator_ex.cpp.html">Std_C++_Allocator</a></li><li><a href="svm_struct_ex.cpp.html">Structural_Support_Vector_Machines</a></li><li><a href="svm_ex.cpp.html">Support_Vector_Machine</a></li><li><a href="svr_ex.cpp.html">Support_Vector_Regression</a></li><li><a href="surf_ex.cpp.html">SURF</a></li><li><a href="svm_rank_ex.cpp.html">SVM-Rank</a></li><li><a href="threaded_object_ex.cpp.html">Threaded_Object</a></li><li><a href="threads_ex.cpp.html">Threads</a></li><li><a href="thread_function_ex.cpp.html">Thread_Function</a></li><li><a href="thread_pool_ex.cpp.html">Thread_Pool</a></li><li><a href="timer_ex.cpp.html">Timer</a></li><li><a href="train_object_detector.cpp.html">Train_Object_Detector</a></li><li><a href="using_custom_kernels_ex.cpp.html">Using_Custom_Kernels</a></li><li><a href="xml_parser_ex.cpp.html">XML_Parser</a></li></ul></li><li><a onclick="Toggle(this)" style="cursor: pointer;margin-left:-9px"><img src="plus.gif"><font color="green"><u>Examples: Python</u></font></a><ul style="display:none;"><li><a href="face_detector.py.html">Face_Detector</a></li><li><a href="max_cost_assignment.py.html">Linear_Assignment_Problems</a></li><li><a href="sequence_segmenter.py.html">Sequence_Segmenter</a></li><li><a href="svm_struct.py.html">Structural_Support_Vector_Machines</a></li><li><a href="svm_rank.py.html">SVM-Rank</a></li><li><a href="train_object_detector.py.html">Train_Object_Detector</a></li></ul></li><li><a href="faq.html">FAQ</a></li><li><a href="index.html">Home</a></li><li><a href="compile.html">How to compile</a></li><li><a href="howto_contribute.html">How to contribute</a></li><li><a href="term_index.html">Index</a></li><li><a href="intro.html">Introduction</a></li><li><a href="license.html">License</a></li><li><a href="python/index.html">Python API</a></li><li><a href="books.html">Suggested Books</a></li></ul><br><b>Current Release</b><ul class="tree"><li><a href="change_log.html">Change Log</a></li><li><a href="release_notes.html">Release Notes</a></li><li>Version: 18.9</li></ul><br></td><td width="1"></td></tr><tr><td valign="bottom"><br><br><br><br><br><br><br><br><br>
      Last Modified:<br>Dec 28, 2012<br><br></td></tr></table></td><td VALIGN="TOP" width="100%" style="border: 1px solid rgb(102,102,102);"><center><h1>Networking</h1></center><br><br><p>
         This page documents tools built on top of the dlib <a href="api.html#sockets">sockets API</a>.
         Therefore, all these tools are focused on providing some kind of higher level networking
         abstraction or service.
      </p></td><td BGCOLOR="#F5F5F5" style="padding:7px; border: 1px solid rgb(102,102,102);" VALIGN="TOP" height="100%"><br><table WIDTH="150" height="100%"><tr><td VALIGN="TOP"><b>Objects</b><ul class="tree"><li><a href="#bridge">bridge</a></li><li><a href="#iosockstream">iosockstream</a></li><li><a href="#linker">linker</a></li><li><a href="#server">server</a></li><li><a href="#server_http">server_http</a></li><li><a href="#server_iostream">server_iostream</a></li><li><a href="#sockstreambuf">sockstreambuf</a></li></ul><br><b>BSP</b><ul class="tree"><li><a href="#bsp_connect">bsp_connect</a></li><li><a href="#bsp_context">bsp_context</a></li><li><a href="#bsp_listen">bsp_listen</a></li><li><a href="#bsp_listen_dynamic_port">bsp_listen_dynamic_port</a></li></ul><br></td><td width="1"></td></tr><tr><td valign="bottom"></td></tr></table></td></tr></table><a name="bridge"><div id="component"><a href="#top"><font size="2"><center>[top]</center></font></a><h1 style="margin:0px;">bridge</h1><BR><BR>
            This object is a tool for bridging a <a href="other.html#pipe">pipe</a> object between
            two network connected applications.  

            <p>
               The bridge object is designed to link two pipes together as efficiently as
               possible.  To demonstrate its speed, I ran two experiments where a bridge was
               used to connect a desktop PC to a laptop, both running Ubuntu 12.04 and
               connected via gigabit ethernet.  The first experiment is to test its bulk
               transfer speed while the second experiment measures how many separate objects
               the bridge can transfer each second.
            </p><p>
               In the first experiment, 1-megapixel images, represented with
               <tt>array&lt;rgb_pixel&gt;</tt> objects, were sent.  The transfer rate was
               112 megabytes/second, saturating the gigabit ethernet link.  The second
               experiment used a <tt>pipe&lt;char&gt;</tt> and <tt>bridge</tt> to send individual
               <tt>char</tt> variables over the network.  In this experiment, I was able to
               send 3.2 million objects a second (i.e. the receiving end was getting a char
               back from pipe::dequeue() 3.2 million times each second).
            </p><p>
               For reference, these experiments were carried out on a desktop with a 2.67GHz
               Intel Core-i7 CPU and a laptop with a 2.20GHz Intel Core-i7 CPU.
            </p><BR><BR><B><font style="font-size:1.4em"><tt>#include &lt;dlib/bridge.h&gt;</tt></font></B><BR><b><a href="dlib/bridge/bridge_abstract.h.html#bridge"><font style="font-size:1.4em">Detailed Documentation</font></a></b><BR>C++ Example Programs: <a href="bridge_ex.cpp.html">bridge_ex.cpp</a><br><br><center></center></div></a><a name="bsp_connect"><div id="component"><a href="#top"><font size="2"><center>[top]</center></font></a><h1 style="margin:0px;">bsp_connect</h1><BR><BR>
              This function spawns a BSP job consisting of a number of network hosts
              as well as the local host.
         <BR><BR><B><font style="font-size:1.4em"><tt>#include &lt;dlib/bsp.h&gt;</tt></font></B><BR><b><a href="dlib/bsp/bsp_abstract.h.html#bsp_connect"><font style="font-size:1.4em">Detailed Documentation</font></a></b><BR>C++ Example Programs: <a href="bsp_ex.cpp.html">bsp_ex.cpp</a><br><br><center></center></div></a><a name="bsp_context"><div id="component"><a href="#top"><font size="2"><center>[top]</center></font></a><h1 style="margin:0px;">bsp_context</h1><BR><BR>
                This is a tool used to implement algorithms using the Bulk Synchronous
                Parallel (BSP) computing model.   In particular, this object defines
                the API used for communication between BSP jobs. 
         <BR><BR><B><font style="font-size:1.4em"><tt>#include &lt;dlib/bsp.h&gt;</tt></font></B><BR><b><a href="dlib/bsp/bsp_abstract.h.html#bsp_context"><font style="font-size:1.4em">Detailed Documentation</font></a></b><BR>C++ Example Programs: <a href="bsp_ex.cpp.html">bsp_ex.cpp</a><br><br><center></center></div></a><a name="bsp_listen"><div id="component"><a href="#top"><font size="2"><center>[top]</center></font></a><h1 style="margin:0px;">bsp_listen</h1><BR><BR>
            This function listens for a TCP connection from the <a href="#bsp_connect">bsp_connect</a> routine.  
            Once this connection is established, a user supplied function will be executed and it will
            then be able to participate in a BSP computation as one of the processing
            nodes.  
         <BR><BR><B><font style="font-size:1.4em"><tt>#include &lt;dlib/bsp.h&gt;</tt></font></B><BR><b><a href="dlib/bsp/bsp_abstract.h.html#bsp_listen"><font style="font-size:1.4em">Detailed Documentation</font></a></b><BR>C++ Example Programs: <a href="bsp_ex.cpp.html">bsp_ex.cpp</a><br><br><center></center></div></a><a name="bsp_listen_dynamic_port"><div id="component"><a href="#top"><font size="2"><center>[top]</center></font></a><h1 style="margin:0px;">bsp_listen_dynamic_port</h1><BR><BR>
            This function listens for a TCP connection from the <a href="#bsp_connect">bsp_connect</a> routine.  
            Once this connection is established, a user supplied function will be executed and it will
            then be able to participate in a BSP computation as one of the processing
            nodes.  This function has the additional ability to select the listening TCP port 
            automatically from the set of available ports.
         <BR><BR><B><font style="font-size:1.4em"><tt>#include &lt;dlib/bsp.h&gt;</tt></font></B><BR><b><a href="dlib/bsp/bsp_abstract.h.html#bsp_listen_dynamic_port"><font style="font-size:1.4em">Detailed Documentation</font></a></b><br><br><center></center></div></a><a name="iosockstream"><div id="component"><a href="#top"><font size="2"><center>[top]</center></font></a><h1 style="margin:0px;">iosockstream</h1><BR><BR>
            This is an iostream object that reads/writes from a TCP network connection.
         <BR><BR><B><font style="font-size:1.4em"><tt>#include &lt;dlib/iosockstream.h&gt;</tt></font></B><BR><b><a href="dlib/iosockstream/iosockstream_abstract.h.html"><font style="font-size:1.4em">Detailed Documentation</font></a></b><BR>C++ Example Programs: <a href="iosockstream_ex.cpp.html">iosockstream_ex.cpp</a><br><br><center></center></div></a><a name="linker"><div id="component"><a href="#top"><font size="2"><center>[top]</center></font></a><h1 style="margin:0px;">linker</h1><BR><BR>
            This object represents something that takes two connections and lets
            them talk to each other.  ie. any incoming data from one connection is
            passed unaltered to the other and vice versa.         
         <BR><BR><B><font style="font-size:1.4em"><tt>#include &lt;dlib/linker.h&gt;</tt></font></B><BR><b><a href="dlib/linker/linker_kernel_abstract.h.html"><font style="font-size:1.4em">Detailed Documentation</font></a></b><br><br><center></center></div></a><a name="server"><div id="component"><a href="#top"><font size="2"><center>[top]</center></font></a><h1 style="margin:0px;">server</h1><BR><BR>
                This object represents a server that listens on a port and spawns new
                threads to handle each new connection. It also manages the connections
                and threads for you.
         <BR><BR><B><font style="font-size:1.4em"><tt>#include &lt;dlib/server.h&gt;</tt></font></B><BR><b><a href="dlib/server/server_kernel_abstract.h.html"><font style="font-size:1.4em">Detailed Documentation</font></a></b><BR>C++ Example Programs: <a href="sockets_ex.cpp.html">sockets_ex.cpp</a><br><br><center></center></div></a><a name="server_http"><div id="component"><a href="#top"><font size="2"><center>[top]</center></font></a><h1 style="margin:0px;">server_http</h1><BR><BR> 
            This is an extension of the <a href="#server_iostream">server_iostream</a> object which
            turns it into a simple HTTP server.
         <BR><BR><B><font style="font-size:1.4em"><tt>#include &lt;dlib/server.h&gt;</tt></font></B><BR><b><a href="dlib/server/server_http_abstract.h.html#server_http"><font style="font-size:1.4em">Detailed Documentation</font></a></b><BR>C++ Example Programs: <a href="server_http_ex.cpp.html">server_http_ex.cpp</a><br><br><center></center></div></a><a name="server_iostream"><div id="component"><a href="#top"><font size="2"><center>[top]</center></font></a><h1 style="margin:0px;">server_iostream</h1><BR><BR> 
            This is an extension of the <a href="#server">server</a> object that redefines
            the on_connect() function so that instead of giving you a connection object you
            get an istream and ostream object.
         <BR><BR><B><font style="font-size:1.4em"><tt>#include &lt;dlib/server.h&gt;</tt></font></B><BR><b><a href="dlib/server/server_iostream_abstract.h.html"><font style="font-size:1.4em">Detailed Documentation</font></a></b><BR>C++ Example Programs: <a href="server_iostream_ex.cpp.html">server_iostream_ex.cpp</a><br><br><center></center></div></a><a name="sockstreambuf"><div id="component"><a href="#top"><font size="2"><center>[top]</center></font></a><h1 style="margin:0px;">sockstreambuf</h1><BR><BR>
            This object represents a stream buffer for connection objects.   If you
            are considering using this object then you should also take a look at
            the <a href="#iosockstream">iosockstream</a>.
         <BR><BR><B><font style="font-size:1.4em"><tt>#include &lt;dlib/sockstreambuf.h&gt;</tt></font></B><BR><b><a href="dlib/sockstreambuf/sockstreambuf_abstract.h.html"><font style="font-size:1.4em">Detailed Documentation</font></a></b><BR>C++ Example Programs: <a href="sockstreambuf_ex.cpp.html">sockstreambuf_ex.cpp</a><br><br><center></center></div></a></div></body></html>
